﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Ymatou.ExcelConvert.Client;
using Ymatou.CommonService;
namespace Sample.Ymatou.File.Web.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to kick-start your ASP.NET MVC application.";

             // public static string UpLoadPicFile(HttpPostedFileBase postedFile, string picType, string savedFileName, out string error)
            return View();
        }


        public string UploadImg()
        {

            HttpPostedFileBase pic = Request.Files[0];

            string savedFileName = DateTime.Now.ToShortDateString().Replace(@"/","") +
                                       Path.GetExtension(pic.FileName);
            string saveErrMsg = "error";
            string result = Uploads.UpLoadPicFile(pic, "product", savedFileName, out saveErrMsg);

            return result;
               
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult Upload()
        {
            HttpPostedFileBase file = Request.Files[0];
            return this.ConvertExcelResult(file);
        }

        public ActionResult UploadExcel2010()
        {
            HttpPostedFileBase file = Request.Files[0];
            return this.ConvertExcelResult(file, "xlexcel12");
        }
    }
}